/*
 * Copyright 2000 - 2009 Ivan Khalopik. All Rights Reserved.
 */

package itdep.ui.components;

import ga.security.UserContext;
import ga.tapestry.commonlib.base.components.AbstractComponent;
import itdep.security.IisUser;
import itdep.ui.pages.security.Login;
import org.apache.tapestry5.Binding;
import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.internal.services.LinkImpl;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.Response;

/**
 * @author Ivan Khalopik
 * @version $Revision: 56 $ $Date: 2010-07-07 10:56:24 +0000 (Wed, 07 Jul 2010) $
 */
@Import(stylesheet = "context:css/main.css")
public class Layout extends AbstractComponent {

	@Parameter(defaultPrefix = BindingConstants.MESSAGE)
	private String title;

	Binding defaultTitle() {
		return newBinding("default title", getResources().getContainerResources(), BindingConstants.PROP, "title");
	}

	@Inject
	private UserContext<IisUser> userContext;

	@Inject
	private Request request;

	@Inject
	private Response response;

	public UserContext<IisUser> getUserContext() {
		return userContext;
	}

	public boolean isAuthorized() {
		return userContext.getCurrentUser() != null;
	}

	public String getTitle() {
		return title;
	}

	Object onLogin() {
		return Login.class;
	}

	Object onLogout() {
		return new LinkImpl(request.getContextPath() + "/security/logout", false, false, response, null);
	}

}
